<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>电灯开关</title>
</head>
<body>
    <img id = "light" onclick = "fun()" src = "img/off.gif">
    <script>
        var flag = false;
        function fun(){
            var light = document.getElementById("light");
            if(flag){
                light.src = "img/off.gif";
                flag = false;
            }else{
                light.src = "img/on.gif";
                flag = true;
            }
        }
    </script>
</body>
</html>